import { TextInput, List, Datagrid, TextField, DateField, Pagination ,Toolbar,SelectInput} from 'react-admin';


import { UploadContactLogBtn } from './UploadContactLogBtn';
import { PushContactRankingToWikiBtn } from './PushContactRankingToWikiBtn'; 
import { useState ,useEffect} from 'react'
import { dataProvider } from '../../dataProvider/DataProvider'
const PostPagination = () => <Pagination rowsPerPageOptions={[25, 50, 100]} />;

export const ContactListPage = () => {
    const [contactEvents,setContactEvents] = useState([]);

    const uploadCode = import.meta.env.VIEW_UPLOAD_CODE_CONTACT_LOG;
    const postFilters = [
        <TextInput label="呼号" source="callsign" alwaysOn />,
         <SelectInput label="通联活动名称" source="event_Id" choices={contactEvents} alwaysOn />
        // <ReferenceArrayInput  source="callsigns" reference="/callsign" alwaysOn />
        // <DateTimeInput label="时间" source="contact_date_time" alwaysOn/>,
    ];

    useEffect(  
        () =>{
            dataProvider.getContactEventDropdown(false,setContactEvents);
        },[]
    )
   // 
    return (

        <List
            filters={postFilters}
            pagination={<PostPagination />} >
            <Toolbar>
                <UploadContactLogBtn uploadCode={uploadCode}
                    label={"导入通联记录"} />
                <PushContactRankingToWikiBtn label={"刷新WIKI通联排行榜"}/>
            </Toolbar>
            <Datagrid>
                <TextField source="id" label="序号" />
                <TextField source="seq" label="通联序号" />
                <TextField source="eventName" label="通联活动" />
                <TextField source="opCallsign" label="OP" />
                <TextField source="callsign" label="呼号" />
                <TextField source="rgi" label="设备" />
                <TextField source="power" label="功率" />
                <TextField source="ant" label="天线" />
                <TextField source="height" label="高度" />
                <TextField source="qth" label="QTH" />
                <DateField source="contactDateTime" label="时间" />
                <TextField source="eventId" label="通联活动ID" />
            </Datagrid>
        </List>
    )
};